<?
$pacth="C:/xampp/htdocs/05_NIV/";
require ($pacth.'DataProvider/DataConnection.php');
Class SystemModule{
	var $_connect;
	function SystemModule() {
        $this->_connect = new _DataConnection();
    }
	function NIVLogin($u,$p){
        $p=md5($p);
        $u=str_replace("'","\'",str_replace("\\","\\\\",$u));
        $SQLCommand="
        select * 
        from `account` where (`identifier`='$u' or `mail`='$u') and `password`='$p'
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
		if($data!=null ) {
            $row=$data->fetch_array();
            if(isset($row["key"])){
            	$_SESSION[ "JO_account_pass"		] = isset($row[ "password"				])?$row[ "password"				]:NULL;
        		$_SESSION[ "JO_account_key"			] = isset($row[ "key"				])?$row[ "key"				]:NULL;
        		$_SESSION[ "JO_account_identifier"	] = isset($row[ "identifier"			])?$row[ "identifier"			]:NULL;
        		$_SESSION[ "JO_account_authority"	] = isset($row[ "authority"			])?$row[ "authority"			]:NULL;
        		$_SESSION[ "JO_account_name"		] = isset($row[ "name"				])?$row[ "name"				]:"NULL";
        		$_SESSION[ "JO_account_mail"		] = isset($row[ "mail"				])?$row[ "mail"				]:NULL;
        		$_SESSION[ "JO_account_phone"		] = isset($row[ "phone"				])?$row[ "phone"				]:NULL;
        		$_SESSION[ "JO_account_address"		] = isset($row[ "address"			])?$row[ "address"			]:NULL;
                $_SESSION[ "JO_account_organ"		] = isset($row[ "organization"			])?$row[ "organization"			]:NULL;
        		$_SESSION[ "JO_account_image"		] = isset($row[ "image"			])?$row[ "image"			]:"";
        		$_SESSION[ "JO_account_quest"		] = isset($row[ "secret_question"			])?$row[ "secret_question"			]:NULL;
        		$_SESSION[ "account_authorityniv"	] = isset($row[ "authorityniv"			])?$row[ "authorityniv"			]:NULL;
        		$this->getSetting();
				return true;
            }else{
            	return false;
            }
            
        }
        return false;
    }
	function getSetting(){
        $SQLCommand="
        select * 
        from `setting` where `key`=1
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
		if($data!=null ) {
            $row=$data->fetch_array();
            if(isset($row["key"])){
            	$labels=array	(
					"bnone"=>$row["bnone"],
					"bred"=>$row["bred"],
					"bblue"=>$row["bblue"],
					"bgreen"=>$row["bgreen"],
					"bpurple"=>$row["bpurple"],
					);
            	$_SESSION[ "label"		] = $labels;
            	$_SESSION[ "numrow"		] = $row["rowdisplay"];
        		return true;
            }else{
            	return false;
            }
            
        }
        return false;
    }
    function NIVLogout(){
    	session_destroy();
    }
	function saveSetting($bnone,$bred,$bblue,$bgreen,$bpurple,$rowdisplay){
        $SQLCommand="
        update 
			`setting`
		set `bnone`='$bnone',`bred`='$bred',`bblue`='$bblue',`bgreen`='$bgreen',`bpurple`='$bpurple',`rowdisplay`=$rowdisplay
		where `key`=1
		";
		
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        if($n==1) {
            return true;
        }
        return false;
    }
}
?>